package com.example.youjingjing.electronicbalance.adapter;


import android.content.Context;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.youjingjing.electronicbalance.R;
import com.example.youjingjing.electronicbalance.dialog.CustomDialog;

import java.util.List;

/**
 * Created by youjingjing on 2017/7/24.
 */

public class MyAdapter extends BaseAdapter<String> {
    CustomDialog mDialog;
    public MyAdapter(Context context, List<String> data, int layoutId) {
            super(context, data, layoutId);
        }

    @Override
    public void onBind(final BaseHolder holder, String s, int position) {
        //根据控件Id获取Item内部的控件
        TextView tvName = holder.getView(R.id.recycle_textview);
        tvName.setText(data.get(position));
        holder.setOnClickListener(R.id.recycle_textview, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mDialog=new CustomDialog(context, "温馨提示", "确定要退出我们可爱的App吗?", "确定",new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mDialog.dismiss();
                        Toast.makeText(context,"退出了--伤心",Toast.LENGTH_LONG).show();

                    }
                });
                mDialog.setCanotBackPress();//设置屏蔽返回键
                mDialog.setCanceledOnTouchOutside(false);
                mDialog.show();
            }
        });
    }
    public void addData(int position){
        data.add(position, "新增" + position);
        //通知适配器item内容插入
        notifyItemInserted(position);
    }
    public void RemoveData(int position){
        data.remove(position);
        //通知适配器item内容删除
        notifyItemRemoved(position);
    }

//    @Override
//    public void onBind(BaseHolder holder, final Contact contact, int position) {
//        //根据控件Id获取Item内部的控件
//        TextView tvName = holder.getView(R.id.tvName);
//        tvName.setText(contact.getName());
//        //根据Item中的控件Id向控件添加事件监听
//        holder.setOnClickListener(R.id.ivPhone, new View.OnClickListener() {
//            @Override
//               public void onClick(View v) {
//                 //自定义的代码
//              }
//        });
//    }

}